﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Toenda.Foundation.Data {
	/// <summary>
	/// Class XmlNodeType
	/// </summary>
	public class XmlNodeTemplate {
		/// <summary>
		/// Default constructor
		/// </summary>
		public XmlNodeTemplate() {
			this.Attributes = new List<XmlAttributeTemplate>();
			this.ChildNodes = new XmlDocumentTemplate();
		}

		/// <summary>
		/// Specific constructor
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="nodeName">Name of the node.</param>
		/// <param name="value">The value.</param>
		public XmlNodeTemplate(
			XmlNodeTemplateType type,
			string nodeName,
			string value) {
			this.Attributes = new List<XmlAttributeTemplate>();
			this.ChildNodes = new XmlDocumentTemplate();

			this.Type = type;
			this.Name = nodeName;
			this.Value = value;
		}

		/// <summary>
		/// Specific constructor
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="nodeName">Name of the node.</param>
		/// <param name="value">The value.</param>
		/// <param name="attribute">The attribute.</param>
		/// <param name="attributeValue">The attribute value.</param>
		public XmlNodeTemplate(
			XmlNodeTemplateType type,
			string nodeName,
			string value,
			string attribute,
			string attributeValue) {
			this.Attributes = new List<XmlAttributeTemplate>();
			this.ChildNodes = new XmlDocumentTemplate();

			this.Type = type;
			this.Name = nodeName;
			this.Value = value;
			this.AttributeName = attribute;
			this.AttributeValue = attributeValue;
		}

		/// <summary>
		/// Specific constructor
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="nodeName">Name of the node.</param>
		/// <param name="value">The value.</param>
		/// <param name="attributes">The attributes.</param>
		public XmlNodeTemplate(
			XmlNodeTemplateType type,
			string nodeName,
			string value,
			List<XmlAttributeTemplate> attributes) {
			this.Attributes = new List<XmlAttributeTemplate>();
			this.ChildNodes = new XmlDocumentTemplate();

			this.Type = type;
			this.Name = nodeName;
			this.Value = value;
			this.Attributes = attributes;
		}

		/// <summary>
		/// Get or set the type
		/// </summary>
		/// <value>The type.</value>
		public XmlNodeTemplateType Type { get; set; }

		/// <summary>
		/// Get or set the node name
		/// </summary>
		/// <value>The name of the node.</value>
		public string Name { get; set; }

		/// <summary>
		/// Get or set the value
		/// </summary>
		/// <value>The value.</value>
		public string Value { get; set; }

		/// <summary>
		/// Get or set the attribute
		/// </summary>
		/// <value>The attribute.</value>
		public string AttributeName { get; set; }

		/// <summary>
		/// Get or set the attribute value
		/// </summary>
		/// <value>The attribute value.</value>
		public string AttributeValue { get; set; }

		/// <summary>
		/// Get or set the attribute templates list
		/// </summary>
		/// <value>The attributes.</value>
		public List<XmlAttributeTemplate> Attributes { get; private set; }

		/// <summary>
		/// Get or set the attribute templates list
		/// </summary>
		/// <value>The children.</value>
		public XmlDocumentTemplate ChildNodes { get; private set; }

		/// <summary>
		/// Get a value that indicates that this element has child nodes
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has attribute; otherwise, <c>false</c>.
		/// </value>
		public bool HasChildNodes {
			get {
				if(this.ChildNodes != null && this.ChildNodes.Count > 0) {
					return true;
				}
				else {
					return false;
				}
			}
		}

		/// <summary>
		/// Get a value that indicates that this element has a attribute
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has attribute; otherwise, <c>false</c>.
		/// </value>
		public bool HasAttribute {
			get {
				if(!this.AttributeName.IsNullOrTrimmedEmpty()
				|| this.Attributes.Count > 0) {
					return true;
				}
				else {
					return false;
				}
			}
		}

		/// <summary>
		/// Get a value that indicates that this element has a attribute
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has attribute; otherwise, <c>false</c>.
		/// </value>
		public bool HasOnlySingleAttribute {
			get {
				if(!this.AttributeName.IsNullOrTrimmedEmpty()
				&& (this.Attributes == null || this.Attributes.Count == 0)) {
					return true;
				}
				else {
					return false;
				}
			}
		}

		/// <summary>
		/// Get a value that indicates that this element has a list of attribute
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has attributes list; otherwise, <c>false</c>.
		/// </value>
		public bool HasAttributeList {
			get {
				if(this.Attributes.Count > 0) {
					return true;
				}
				else {
					return false;
				}
			}
		}
	}
}
